﻿/// <reference path="jquery-1.4.2.min-vsdoc.js"/>
/// <reference path="../config/sw-config-default.js"/>
/// <reference path="../const/sw-const.js"/>
/// <reference path="sw-prototype.js"/>
/// <reference path="sw.js"/>
/// <reference path="sw-control-core.js"/>

$icontrol = function () {
    /// <summary>Smart UI 控件库,初始化控件</summary>
}

///#region button
/// <reference path="../plugins/button.js"/>
$icontrol.button = function (options, btnid) {
    /// <summary>生成button对象或者是Html文本</summary>    
    /// <param name="options" type="Array">button的设置项</param>
    /// <param name="btnid" type="String">btn id</param> 
    /// <returns type="String || JQDom" />
    return $.button(btnid || '', options);
}
$icontrol.buttonSet = function (btn, isEnable) {
    /// <summary>设置button是否可用</summary>    
    /// <param name="ctr" type="Dom||JQSelect">btn</param> 
    /// <param name="options" type="Array">【非必要属性】,datepicker的设置项</param>
    /// <returns type="JQDom" />
    return $(btn).buttonSet(isEnable);
}
///#endregion

///#region datepicker
/// <reference path="../plugins/datepicker.js"/>
$icontrol.datepicker = function (ctr,options) {
    /// <summary>初始化datepicker</summary>    
    /// <param name="ctr" type="Dom||JQSelect">input控件</param> 
    /// <param name="options" type="Array">【非必要属性】,datepicker的设置项</param>
   return $(ctr).datepicker(options);
}
///#endregion

///#region chooser 2010-7-21 RoyZhang
/// <reference path="../plugins/chooser.js"/>
$icontrol.chooserbydata = function (ctr, options, jsndata) {
    /// <summary>根据数据源，生成选择控件，注：控件设置属性ename，可以读取定义的枚举数据源</summary>
    /// <param name="ctr" type="Dom||JQSelect">触发选择的input控件,类型可以为对象也可以为JQ选择字符</param>
    /// <param name="options" type="Array">设置项</param>
    /// <param name="jsnData" type="Json">【非必要属性】,Json格式数据集合（非ajax方式）</param>
    /// <returns type="JQDom" />
    options.css = iconfig.chooser.css;
    if (!jsndata && options.ename && options.ename.length > 0)
        jsndata = $sw.getEnum(options.ename); //当为枚举数据源时

    return $(ctr).chooser(options, jsndata);
}

$icontrol.chooser = function (ctr,  options) {
    /// <summary>初始化选择控件，注：控件设置属性ename，可以读取定义的枚举数据源</summary>    
    /// <param name="ctr" type="Dom||JQSelect">触发选择的input控件,类型可以为对象也可以为JQ选择字符</param>
    /// <param name="options" type="Array">chooser的设置项</param>
    /// <returns type="JQDom" />
    ctr = $(ctr);
    if (!options)
        options = {};
    var ename = ctr.attr('ename');
    var jsnData, ajax;
    if (ename && ename.length > 0)
        jsnData = $sw.getEnum(ename);
    else
        options.ajax = ictrcore.setPsaAjax(ctr.attr('fncode'));

    return $icontrol.chooser.bind(ctr, options, jsnData);
}
//$icontrol.chooser.bind = function (ctr, options, jsndata) {
//    /// <summary>重新绑定选择控件</summary>    
//    /// <param name="ctr" type="JQDom">触发选择的input控件,类型可以为对象也可以为JQ选择字符</param>
//    /// <param name="options" type="Array">chooser的设置项</param>
//    /// <param name="jsnData" type="Json">【非必要属性】,Json格式数据集合（非ajax方式）</param>
//    /// <returns type="JQDom" />
//    if (!options)
//        options = {};
//    if (options.type == 'list')
//        return ctr.chooser(options, jsndata);
//    else
//        return ctr.chooser(options, jsndata);
//}
$icontrol.chooser.setValue = function (ctr, value) {
    /// <summary>设置选择控件的值</summary>    
    /// <param name="chooser" type="Dom||JQSelect">触发选择的input控件,类型可以为对象也可以为JQ选择字符</param>
    /// <param name="value" type="String">需要设置的值</param>
    /// <returns type="JQDom" />
    return $(chooser).chooserSetValue(value);
}
$icontrol.chooser.reload = function (ctr, ajax, jsndata) {
    /// <summary>初始化选择控件使用数据源</summary>    
    /// <param name="ctr" type="JQDom">触发选择的input控件</param>
    /// <param name="datas" type="String">需要设置的值</param>
    /// <param name="jsnData" type="Json">【非必要属性】,Json格式数据源</param>
    /// <returns type="JQDom" />
    return $(ctr).chooserReload(ajax, jsndata);
}
///#endregion

///#region grid 2010-7-29 RoyZhang
/// <reference path="../plugins/gridview.js"/>
$icontrol.grid = function (ctr, options, fncode, postdata) {
    /// <summary>初始化grid控件</summary>    
    /// <param name="ctr" type="Dom || JQSelect">容器控件对象或是id选择器</param>
    /// <param name="options" type="Array">Grid的设置项</param>
    /// <param name="fncode" type="String">Function Code</param>    
    /// <param name="postdata" type="String || Json">【非必要属性】,发送的参数，json字串或是Json对象</param>
    options.ajax = ictrcore.setPsaAjax(fncode, postdata);
    $(ctr).gridview(options);
}
$icontrol.grid.reload = function (ctr, fncode, postdata, options) {
    /// <summary>重新加载grid</summary>    
    /// <param name="ctr" type="Dom || JQSelect">容器控件对象或是id选择器</param>
    /// <param name="fncode" type="String">Function Code</param>    
    /// <param name="postdata" type="String || Json">【非必要属性】,Post Data json字串或是Json对象</param>
    /// <param name="options" type="Array">【非必要属性】,Grid的设置项</param>
    if (!options && fncode) {
        options = {};
        options.ajax = ictrcore.setPsaAjax(fncode, postdata);
    }
    $(ctr).girdviewReload(options);
}
///#endregion

///#region pager 2010-8-2 RoyZhang
/// <reference path="../plugins/pager.js"/>
$icontrol.pager = function (ctr, totalrecord, fnpagechanged, options) {
    /// <summary>初始化翻页控件</summary>    
    /// <param name="ctr" type="Dom || JQSelect">容器控件对象或是id选择器</param>
    /// <param name="totalrecord" type="String">总记录数</param>    
    /// <param name="fnpagechanged" type="Function">翻页执行的操作</param>
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    options.totalrecord = totalrecord;
    $(ctr).pager(options, fnpagechanged);
}
$icontrol.pager.change = function (ctr, pageindex, fnpagechanged) {
    /// <summary>翻页控件翻页方法</summary>    
    /// <param name="ctr" type="Dom || JQSelect">容器控件对象或是id选择器</param>
    /// <param name="pageindex" type="Number">页码</param>
    /// <param name="fnpagechanged" type="Function">【非必要属性】,成功后执行的操作,success()</param>
    $(ctr).pagerChange(pageindex, fnpagechanged);
}
///#endregion

///#region repeat 2010-9-1 RoyZhang
/// <reference path="../plugins/repeat.js"/>
$icontrol.repeat = function (ctr, template, fncode, options, postdata) {
    /// <summary>初始化repeat控件</summary>    
    /// <param name="ctr" type="Dom || JQSelect">容器控件对象或是id选择器</param>
    /// <param name="template" type="String">html模板或是模板id选择器</param>    
    /// <param name="fncode" type="String">Function Code</param>    
    /// <param name="options" type="Array">设置项</param>
    /// <param name="postdata" type="String || Json">【非必要属性】,Post Data json字串或是Json对象</param>
    if (!options)
        options = {};
    options.ajax = ictrcore.setPsaAjax(fncode, postdata);
    $(ctr).repeat(options, template);
}
$icontrol.repeat.reload = function (ctr, fncode, postdata, options) {
    /// <summary>重新加载repeat</summary>    
    /// <param name="ctr" type="Dom || JQSelect">容器控件对象或是id选择器</param>
    /// <param name="template" type="String">html模板或是模板id选择器</param>    
    /// <param name="fncode" type="String">Function Code</param>    
    /// <param name="options" type="Array">设置项</param>
    /// <param name="postdata" type="String || Json">【非必要属性】,Post Data json字串或是Json对象</param>
    if (!options && fncode) {
        options = {};
        options.ajax = ictrcore.setPsaAjax(fncode, postdata);
    }
    $(ctr).repeatReload(options);
}
///#endregion

///#region list 2010-7-20 RoyZhang
$icontrol.list = function (ctr, template, jsndatas) {
    /// <summary>根据数据源和模板数据生成列表</summary>    
    /// <param name="ctr" type="Dom || JQSelect">控件对象或id选择器</param>
    /// <param name="template" type="String || JQSelect">模板字串(如：<li lv="${Key}">${Value}</li>)或者是包括模板的对象选择器的ID,如:"#id"</param>
    /// <param name="jsndatas" type="Json">Json格式数据集合</param>

    return ictrcore.teml(ctr, template, jsndatas);
}

$icontrol.list.ajax = function (ctr, template, fncode, postdata, fnsucess, fnerror) {
    /// <summary>根据funcode和模板数据生成列表</summary>    
    /// <param name="ctr" type="Dom || JQSelect">容器的选择器的字串</param>
    /// <param name="template" type="String || JQSelect">模板字串(如：<li lv="${Key}">${Value}</li>)或者是包括模板的对象选择器的ID,如:"#id"</param>
    /// <param name="fncode" type="String">Function Code</param>    
    /// <param name="postdata" type="String || Json">【非必要属性】,发送的参数,json字串或是Json对象</param>
    /// <param name="fnsucess" type="Function">【非必要属性】,成功后执行的操作,success(data,container),data：json数据、container容器控件</param>
    /// <param name="fnerror" type="Function">【非必要属性】,请求失败后的操作</param>
    ictrcore.teml(ctr, template, fncode, postdata, fnsucess, fnerror);
}
///#endregion

///#region modalwin
$icontrol.modalwin = function (url, width, height, id, title) {
    ///<summary>打开模态窗口</summary>
    ///<param name="url" type="String">目标地址</param>
    ///<param name="width" type="Number">窗口宽度</param> 
    ///<param name="height" type="Number">窗口高度</param>
    ///<param name="id" type="String">【非必要属性】,弹出win的id</param>
    ///<param name="title" type="String">【非必要属性】,win的title</param>   
   
    $.modalWin({ id: id, url: url, title: title, width: width, height: height });
};
$icontrol.modalwinClose = function () {
    ///<summary>关闭模态窗口</summary>
    $.modalPanelClose('win');
}
///#endregion

///#region message
$icontrol.alert = function (msg, fnok, type) {
    ///<summary>弹出消息方法</summary>
    ///<param name="msg" type="String">弹出消息</param>  
    ///<param name="fnok" type="Function">【非必要属性】,确定后执行的方法</param> 
    /// <param name="type" type="String">【非必要属性】,消息类型</param>
    $.message(msg, { showtype: type, fnok: fnok });
}
$icontrol.alertAndGoto = function (msg, url, type) {
    ///<summary>弹出消息，点击确定后跳转</summary>
    ///<param name="msg" type="String">弹出消息</param>   
    ///<param name="url" type="String">跳转页面路径【UICode】</param>
    /// <param name="type" type="String">【非必要属性】,消息类型</param>
    $.message(msg, { showtype: type, fnok: function () { $sw.GotoPage(url); } });
}
$icontrol.show = function (msg, type, timeout) {
    ///<summary>显示消息方法</summary>
    ///<param name="msg" type="String">显示消息</param>   
    /// <param name="type" type="String">【非必要属性】,消息类型</param>    
    /// <param name="timeout" type="Number">【非必要属性】,显示时间</param>
    $.message(msg, { type: 'show', showtype: type, timeout: timeout });
}
$icontrol.confirm = function (msg, fnpass, fncancel) {
    ///<summary>confirm操作</summary>
    ///<param name="msg"  type="String">确认消息</param>
    ///<param name="fnpass"  type="Function">通过执行的方法</param>   
    ///<param name="fncancel"  type="Function">【非必要属性】,取消执行的方法</param>
    if (!msg)
        msg = $iconst.Common.confirm;
    $.message(msg, { type: 'confirm', fnok: fnpass, fncancel: fncancel });
};
///#endregion

///#region tooltip
/// <reference path="../plugins/tooltip.js"/>
$icontrol.tooltip = function (selector, options) {
    /// <summary>tooltip</summary>    
    /// <param name="selector" type="JQSelect">需要显示tool的对象的选择字串</param>
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    $(selector).tooltip(options);
}
///#endregion

///#region menu
/// <reference path="../plugins/menu.js"/>
$icontrol.menu = function (selector, datas, options) {
    /// <summary>根据数据源创建Menu</summary>    
    /// <param name="selector" type="JQSelect">menu的容器控件</param>
    /// <param name="datas" type="Json">数据源</param>   
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    $(selector).menu(datas, options);
}
$icontrol.menu.ajax = function (selector,fncode, postdata,options) {
    /// <summary>Ajax方式生成menu</summary>    
    /// <param name="selector" type="JQSelect">menu的容器控件</param>
    /// <param name="fncode" type="String">function code</param>
    /// <param name="postdata" type="String || Json">【非必要属性】,请求发送的数据</param> 
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    ictrcore.GetDatas(fncode, postdata, function (datas) {
        if(datas)
            $(selector).menu(datas, options);
     });
}
$icontrol.accordion = function (selector, datas, options) {
    /// <summary>根据数据源创建accordion</summary>    
    /// <param name="selector" type="Select">accordion的容器控件</param>
    /// <param name="datas" type="Json">数据源</param>   
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    $(selector).accordion(datas, options);
}
$icontrol.accordion.ajax = function (selector, fncode, postdata, options) {
    /// <summary>Ajax方式生成accordion</summary>    
    /// <param name="selector" type="JQSelect">menu的容器控件</param>
    /// <param name="fncode" type="String">function code</param>
    /// <param name="postdata" type="String || Json">【非必要属性】,请求发送的数据</param> 
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    ictrcore.GetDatas(fncode, postdata, function (datas) {
        if (datas)
            $(selector).accordion(datas, options);
    });
}
///#endregion

///#region tabs
/// <reference path="../plugins/tabs.js"/>
$icontrol.tabs = function (selector, ctrcontent, datas, options) {
    /// <summary>根据数据源创建tabs</summary>    
    /// <param name="selector" type="JQSelect">容器控件选择器</param>
    /// <param name="ctrcontent" type="Dom || JQSelect">加载的内容区域选择器</param>
    /// <param name="datas" type="Json">数据源</param>   
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    $(selector).tabs(ctrcontent, datas, options);
}
$icontrol.tabs.ajax = function (selector, ctrcontent, fncode, postdata,options) {
    /// <summary>Ajax方式生成accordion</summary>    
    /// <param name="selector" type="JQSelect">容器控件选择器</param>
    /// <param name="ctrcontent" type="Dom || JQSelect">加载的内容区域选择器</param>
    /// <param name="fncode" type="String">function code</param>
    /// <param name="postdata" type="String || Json">【非必要属性】,请求发送的数据</param> 
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    ictrcore.GetDatas(fncode, postdata, function (datas) {
        if (datas)
            $(selector).tabs(ctrcontent, datas, options);
    });
}
$icontrol.tabs.select = function (ctr, index) {
    /// <summary>根据index选择tab</summary>    
    /// <param name="ctr" type="JQSelect">tab控件选择字串</param>
    /// <param name="index" type="Number">显示的tab的Index</param>
    $.tabSelect(ctr, index);
}
///#endregion

///#region sitemap
/// <reference path="../plugins/sitemap.js"/>
$icontrol.sitemap = function (selector, options) {
    /// <summary>tooltip</summary>    
    /// <param name="selector" type="JQSelect">容器控件选择器</param>
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    if (options == null)
        options = {};
    if (iconfig.system.isloadUI && !options.isbuilded) {
        options.isbuilded = true;
        $sw.addGlobalFn(function () { $(selector).sitemap(options); });
    }
    $(selector).sitemap(options);
}
///#endregion

///#region tree
/// <reference path="../plugins/tree.js"/>
$icontrol.tree = function (selector, datas, options) {
    /// <summary>初始化Tree，可根据静态html或数据源</summary>    
    /// <param name="selector" type="JQSelect">容器选择字串</param>
    /// <param name="datas" type="Json">【非必要属性】,数据源</param>   
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    $(selector).tree(datas, options);
}
$icontrol.tree.ajax = function (selector, fncode, postdata, options) {
    /// <summary>Ajax方式生产tree</summary>
    /// <param name="selector" type="JQSelect">容器选择字串</param>
    /// <param name="fncode" type="String">function code</param>
    /// <param name="postdata" type="String || Json">【非必要属性】,请求发送的数据</param> 
    /// <param name="options" type="Array">【非必要属性】,属性设置项</param>
    ictrcore.GetDatas(fncode, postdata, function (datas) {
        if (datas)
            $(selector).tree(datas, options);
    });
}
$icontrol.tree.getTreeValue = function (treeid, chkprop, valuesplit) {
    /// <summary>获取tree中选择的值,仅对多选有效</summary>
    /// <param name="treeid" type="String">tree的ID</param>
    /// <param name="chkprop" type="String">【非必要属性】,chk定义的属性名称,默认'v'</param>   
    /// <param name="valuesplit" type="String">【非必要属性】,值的分割符，默认取系统统一定义</param>
    /// <returns type="String" />
   return $.treeGetValue(treeid, chkprop, valuesplit);
}
///#endregion






